//
//  UserAccount.m
//  kuangjia
//
//  Created by 张帅 on 15/9/28.
//  Copyright © 2015年 ZhangShuai. All rights reserved.
//


#import "UserAccount.h"



@implementation UserAccount


+ (instancetype)userAccountWithDict:(NSDictionary *)dict{
    
    UserAccount *account =[[self alloc] init];

    account.access_token = dict[@"access_token"];
    account.uid = dict[@"uid"];
    account.expires_in = dict[@"expires_in"];
    account.avatar_large =dict[@"avatar_large"];
    account.name = dict[@"name"];
    // 获得账号存储的时间（accessToken的产生时间）
    account.expiresDate = [NSDate date];
    
    return account;
}



-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
    
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeObject:self.access_token forKey:@"access_token"];
    [encoder  encodeObject:self.expires_in forKey:@"expires_in"];
    [encoder encodeObject:self.uid forKey:@"uid"];
    [encoder encodeObject:self.expiresDate forKey:@"expiresDate"];
    [encoder encodeObject:self.name forKey:@"name"];
    [encoder encodeObject:self.avatar_large forKey:@"avatar_large"];
    
}

/**
 *  当从沙盒中解档一个对象时（从沙盒中加载一个对象时），就会调用这个方法
 *  目的：在这个方法中说明沙盒中的属性该怎么解析（需要取出哪些属性）
 */
- (id)initWithCoder:(NSCoder *)decoder
{
    if (self = [super init]) {
        self.access_token = [decoder decodeObjectForKey:@"access_token"];
        self.expires_in = [decoder decodeObjectForKey:@"expires_in"];
        self.uid = [decoder decodeObjectForKey:@"uid"];
        self.name  =[decoder decodeObjectForKey:@"name"];
        self.expiresDate =[decoder decodeObjectForKey:@"expiresDate"];
        self.avatar_large =[decoder decodeObjectForKey:@"avatar_large"];
    
    }
    return self;
}


-(NSString *)description{

    NSArray *key = @[@"access_token",@"expires_in",@"uid",@"avatar_large",@"expiresDate",@"name"];
    
    return [self dictionaryWithValuesForKeys:key].description;
//    return [NSString stringWithFormat:@"%@ %@ %@",self.access_token,self.expiresDate,self.name];
    //   // KVC 的模型转字典 "\(变量名)" 调用 description 进行转换
    //return "\(dictionaryWithValuesForKeys(keys))"


}


@end
